package edu.neu.cs6515.xml;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import edu.neu.cs6515.board.BoardCoord;

/**
 * Bean to represent info of game placement by a player in XML format. Example:
 * {@code
 * <placement c0=Color d0=Nat a0=Nat c1=Color d1=Nat a1=Nat />
 * }
 */
@XmlRootElement
@NoArgsConstructor
@EqualsAndHashCode
public final class Placement {

    /**
     * Initializes a placement (no player id is given, placement is assigned
     * based on order in xml)
     * 
     * @param c0
     *            Color of first hexagon
     * @param c1
     *            Color of second hexagon
     * @param d0
     *            Distance of first hexagon
     * @param a0
     *            Angle of first hexagon
     * @param d1
     *            Distance of second hexagon
     * @param a1
     *            Angle of second hexagon
     */
    public Placement(final IngeniousColor c0, final IngeniousColor c1,
            final int d0, final int a0, final int d1, final int a1) {
        this.c0 = c0;
        this.c1 = c1;
        this.d0 = d0;
        this.a0 = a0;
        this.d1 = d1;
        this.a1 = a1;
    }

    private IngeniousColor c0, c1;

    private int d0, a0, d1, a1;

    @XmlAttribute(required = true)
    @XmlJavaTypeAdapter(IngeniousColorAdapter.class)
    public IngeniousColor getC0() {
        return c0;
    }

    public void setC0(final IngeniousColor c0) {
        this.c0 = c0;
    }

    @XmlAttribute(required = true)
    @XmlJavaTypeAdapter(IngeniousColorAdapter.class)
    public IngeniousColor getC1() {
        return c1;
    }

    public void setC1(final IngeniousColor c1) {
        this.c1 = c1;
    }

    @XmlAttribute(required = true)
    public int getD0() {
        return d0;
    }

    public void setD0(final int d0) {
        this.d0 = d0;
    }

    @XmlAttribute(required = true)
    public int getA0() {
        return a0;
    }

    public void setA0(final int a0) {
        this.a0 = a0;
    }

    @XmlAttribute(required = true)
    public int getD1() {
        return d1;
    }

    public void setD1(final int d1) {
        this.d1 = d1;
    }

    @XmlAttribute(required = true)
    public int getA1() {
        return a1;
    }

    public void setA1(final int a1) {
        this.a1 = a1;
    }

    public BoardCoord getBoardCoord0() {
        return new BoardCoord(getD0(), getA0());
    }

    public BoardCoord getBoardCoord1() {
        return new BoardCoord(getD1(), getA1());
    }

    /**
     * to generate Placement to XML String in the format of: <placement c0=Color
     * d0=Nat a0=Nat c1=Color d1=Nat a1=Nat /> where Color is one of
     * IngeniousColor
     * 
     * @return the xml representation of a Placement
     */
    public String toXMLString() {
        return "<placement c0=\"" + this.getC0() + "\" d0=\"" + this.getD0()
                + "\" a0=\"" + this.getA0() + "\" c1=\"" + this.getC1()
                + "\" d1=\"" + this.getD1() + "\" a1=\"" + this.getA1()
                + "\" />";
    }
}
